package com.qfedu.stussm.controller;

import com.qfedu.stussm.entity.Email;
import com.qfedu.stussm.entity.Score;
import com.qfedu.stussm.service.intf.EmailService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/email/")
public class EmailController {
    @Autowired
    private EmailService emailService;
    //    查询
    @GetMapping("emaillist.do")
    @ResponseBody
    public PageBeanVo page(int page, int limit){
        PageBeanVo pageBeanVo = emailService.selectAll(page, limit);
        return pageBeanVo;
    }
    //    新增
    @PostMapping("save.do")
    public String save(Email email){
        emailService.add(email);
        return "redirect:/emaillist.html";
    }
    //    修改
    @PostMapping("update.do")
    @ResponseBody
    public R update(Email email){
        System.out.println(email);
        return emailService.update(email);
    }
    //    s删除
    @PostMapping("del.do")
    @ResponseBody
    public R del(int id){
        return emailService.del(id);
    }
}
